{% import 'Dockerfile/docker.jinja2' as docker %}
{% import 'Dockerfile/provision.jinja2' as provision %}
{% import 'Dockerfile/baselayout.jinja2' as baselayout %}

{% macro guywithnose(release) -%}
USER root

COPY ./solr/ /tmp/solr

{{ baselayout.copy() }}

WORKDIR /

RUN pacman --sync --noconfirm --noprogressbar --quiet net-tools \
    && /usr/local/bin/generate-dockerimage-info \
    && rm -rf /opt/solr/server \
    && mv /opt/solr/example/ /opt/solr/server/ \
    && rm -rf /opt/solr/server/solr \
    && mv /tmp/solr /opt/solr/server/solr \
    && mkdir -p /opt/solr/server/solr/typo3lib \
    && curl -sf -o /opt/solr/server/solr/typo3lib/solr-typo3-plugin.jar -L https://github.com/TYPO3-Solr/solr-typo3-plugin/releases/download/release-{{ release|replace(".", "_") }}/solr-typo3-plugin-{{ release }}.jar \
    && ln -s /opt/solr/contrib /opt/solr/server/solr/contrib \
    && mkdir -p /opt/solr/server/solr/data \
    && ln -s /opt/solr/server/solr/data /opt/solr/server/solr/typo3cores/data \
    && chown -R solr:solr /opt/solr/server/solr/ \
    {{ docker.cleanup() }}

USER solr

WORKDIR /opt/solr/server

VOLUME ["/opt/solr/server/solr/data"]
{%- endmacro %}


{% macro official(version) -%}
USER root

{{ baselayout.copy() }}

RUN apt-update \
    && apt-install net-tools \
    && generate-dockerimage-info \
    && mkdir /tmp/solr \
    && wget -O/tmp/solr/extension.tar.gz "https://github.com/TYPO3-Solr/ext-solr/archive/{{ version }}.tar.gz" \
    && cd /tmp/solr \
    && tar --strip 1 -zxf /tmp/solr/extension.tar.gz \
    && rm -rf /opt/solr/server/solr \
    && mv /tmp/solr/Resources/Private/Solr/ /opt/solr/server/solr \
    && mkdir -p /opt/solr/server/solr/data \
    && chown -R solr:solr /opt/solr/server/solr \
    && chmod 755 /opt/solr/server/solr \
    && rm -rf /tmp/solr \
    {{ docker.cleanup() }}

USER solr

VOLUME ["/opt/solr/server/solr/data"]
{%- endmacro %}
